package org.zhs.tree;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: zhs
 * @Date: 2024/5/7 21:16
 * @Version: 1.0
 * @Description:
 */
public class Demo_MyBinarySearchTree {
    public static void main(String[] args) {
        // 这是最坏的情况，已经变成了一个链表
        MyBinarySearchTree<Integer> tree = new MyBinarySearchTree<>();
        for (int i = 0; i < 10; i++) {
            tree.insert(i);
        }
        System.out.println("初始化完成一棵树");
        System.out.println("=================================================");

        int value = 10;
        System.out.println("是否包含：" + value + "? " + tree.contains(value));
        System.out.println("=================================================");

        Integer min = tree.findMin();
        Integer max = tree.findMax();
        System.out.println("最小值为:" + min + " 最大值为：" + max);
        System.out.println("=================================================");


        System.out.println("=================================================");
        System.out.println("重新构建一个树");
        List<Integer> list = Arrays.asList(9,6,5,7,8,15,10,16,17);
        MyBinarySearchTree<Integer> tree2 = new MyBinarySearchTree<>();
        for (int i = 0; i < list.size(); i++) {
            tree2.insert(list.get(i));
        }
        System.out.println("=================================================");

        tree2.remove(16);
        System.out.println("删除了16");
        System.out.println("=================================================");


        tree2.prePrint();
        System.out.println("前序遍历打印");
        System.out.println("=================================================");



        tree2.midPrint();
        System.out.println("中序遍历打印");
        System.out.println("=================================================");


        tree2.postPrint();
        System.out.println("后序遍历打印");
        System.out.println("=================================================");
    }
}
